2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
8 namespace SuperPolarity
12 private Random random;
13 public Vector2 EmitterLocation { get; set; }
14 private List<Particle> particles;
15 private List<Texture2D> textures;
17 public ParticleEngine(List<Texture2D> textures, Vector2 location)
19 EmitterLocation = location;
20 this.textures = textures;
21 this.particles = new List<Particle>();
22 random = new Random();
25 private Particle GenerateNewParticle()
27 Texture2D texture = textures[random.Next(textures.Count)];
28 Vector2 position = EmitterLocation;
29 Vector2 velocity = new Vector2(
30 1f * (float)(random.NextDouble() * 2 - 1),
31 1f * (float)(random.NextDouble() * 2 - 1));
33 float angularVelocity = 0.1f * (float)(random.NextDouble() * 2 - 1);
34 Color color = new Color(
35 (float)random.NextDouble(),
36 (float)random.NextDouble(),
37 (float)random.NextDouble());
38 float size = (float)random.NextDouble();
40 int ttl = 20 + random.Next(40);
42 return new Particle(texture, position, velocity, angle, angularVelocity, color, size, ttl);
49 for (int i = 0; i < total; i++)
51 particles.Add(GenerateNewParticle());
54 for (int particle = 0; particle < particles.Count; particle++)
56 particles[particle].Update();
57 if (particles[particle].TTL <= 0)
59 particles.RemoveAt(particle);
65 public void Draw(SpriteBatch spriteBatch)
67 //spriteBatch.Begin();
68 for (int index = 0; index < particles.Count; index++)
70 particles[index].Draw(spriteBatch);